-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[NFC][TableGen] Use IfGuardEmitter in CallingConvEmitter
#168763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🐧 Linux x64 Test Results
|
|
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesUse Full diff: https://github.com/llvm/llvm-project/pull/168763.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/CallingConvEmitter.cpp b/llvm/utils/TableGen/CallingConvEmitter.cpp
index e0d933723ad66..5b3a97623ddf8 100644
--- a/llvm/utils/TableGen/CallingConvEmitter.cpp
+++ b/llvm/utils/TableGen/CallingConvEmitter.cpp
@@ -15,6 +15,7 @@
#include "Common/CodeGenTarget.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/InterleavedRange.h"
+#include "llvm/TableGen/CodeGenHelpers.h"
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TGTimer.h"
@@ -54,6 +55,21 @@ class CallingConvEmitter {
};
} // End anonymous namespace
+static void emitCCHeader(raw_ostream &O, const Record *CC, StringRef Suffix) {
+ unsigned Pad = CC->getName().size();
+ if (CC->getValueAsBit("Entry")) {
+ O << "bool llvm::";
+ Pad += 12;
+ } else {
+ O << "static bool ";
+ Pad += 13;
+ }
+ O << CC->getName() << "(unsigned ValNo, MVT ValVT,\n"
+ << std::string(Pad, ' ') << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n"
+ << std::string(Pad, ' ')
+ << "ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State)" << Suffix;
+}
+
void CallingConvEmitter::run(raw_ostream &O) {
emitSourceFileHeader("Calling Convention Implementation Fragment", O);
@@ -63,35 +79,20 @@ void CallingConvEmitter::run(raw_ostream &O) {
// Emit prototypes for all of the non-custom CC's so that they can forward ref
// each other.
Records.getTimer().startTimer("Emit prototypes");
- O << "#ifndef GET_CC_REGISTER_LISTS\n\n";
+ IfGuardEmitter IfGuard(O, "!defined(GET_CC_REGISTER_LISTS)");
for (const Record *CC : CCs) {
- if (!CC->getValueAsBit("Custom")) {
- unsigned Pad = CC->getName().size();
- if (CC->getValueAsBit("Entry")) {
- O << "bool llvm::";
- Pad += 12;
- } else {
- O << "static bool ";
- Pad += 13;
- }
- O << CC->getName() << "(unsigned ValNo, MVT ValVT,\n"
- << std::string(Pad, ' ') << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n"
- << std::string(Pad, ' ')
- << "ISD::ArgFlagsTy ArgFlags, Type *OrigTy, CCState &State);\n";
- }
+ if (!CC->getValueAsBit("Custom"))
+ emitCCHeader(O, CC, ";\n");
}
// Emit each non-custom calling convention description in full.
Records.getTimer().startTimer("Emit full descriptions");
for (const Record *CC : CCs) {
- if (!CC->getValueAsBit("Custom")) {
+ if (!CC->getValueAsBit("Custom"))
emitCallingConv(CC, O);
- }
}
emitArgRegisterLists(O);
-
- O << "\n#endif // CC_REGISTER_LIST\n";
}
void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) {
@@ -105,18 +106,7 @@ void CallingConvEmitter::emitCallingConv(const Record *CC, raw_ostream &O) {
AssignedRegsMap[CurrentAction] = {};
O << "\n\n";
- unsigned Pad = CurrentAction.size();
- if (CC->getValueAsBit("Entry")) {
- O << "bool llvm::";
- Pad += 12;
- } else {
- O << "static bool ";
- Pad += 13;
- }
- O << CurrentAction << "(unsigned ValNo, MVT ValVT,\n"
- << std::string(Pad, ' ') << "MVT LocVT, CCValAssign::LocInfo LocInfo,\n"
- << std::string(Pad, ' ') << "ISD::ArgFlagsTy ArgFlags, Type *OrigTy, "
- << "CCState &State) {\n";
+ emitCCHeader(O, CC, " {\n");
// Emit all of the actions, in order.
for (unsigned I = 0, E = CCActions->size(); I != E; ++I) {
const Record *Action = CCActions->getElementAsRecord(I);
|
s-barannikov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
24dda0e to
d33c38c
Compare
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Use `IfGuardEmitter` in CallingConvEmitter. Additionally refactor the code a bit to extract duplicated code to emit the CC function prototype into a helper function.
d33c38c to
6c7edd7
Compare
Use
IfGuardEmitterin CallingConvEmitter. Additionally refactor the code a bit to extract duplicated code to emit the CC function prototype into a helper function.